package com.ross.mode.two;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * @version 1.0.0
 * @className: MapperProxy
 * @description:
 * @author: zhangjunfa
 * @date: 2023/8/29 10:06
 */
public class MapperProxy<T> implements InvocationHandler {

    private Map<String, String> sqlSession;
    private final Class<T> mapperInterface;

    public MapperProxy(Map<String, String> sqlSession, Class<T> mapperInterface) {
        this.sqlSession = sqlSession;
        this.mapperInterface = mapperInterface;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (Object.class.equals(method.getDeclaringClass())) {
            return method.invoke(this, args);
        }
        // final MapperMethod mapperMethod = cachedMapperMethod(method);
        // return mapperMethod.execute(sqlSession, args);
        return "你被代理了！" + sqlSession.get(mapperInterface.getName() + "." + method.getName());
    }
}
